package com.iafme.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iafme.dto.req.ProcessReqDTO;
import com.iafme.dto.res.ProcessResDTO;
import com.iafme.model.Process;
import com.iafme.model.ProcessMapper;
import com.iafme.service.ProcessService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author summer
 * @version 1.0
 * @date 2025/2/21 20:52
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ProcessServiceImpl extends ServiceImpl<ProcessMapper, Process> implements ProcessService {
    @Override
    public Page<ProcessResDTO> lists(ProcessReqDTO processReqDTO) {
        Page<Process> page=new Page<>(processReqDTO.getPageNum(), processReqDTO.getPageSize());
        LambdaQueryWrapper<Process> eq = Wrappers.lambdaQuery(Process.class).eq(ObjectUtil.isNotEmpty(processReqDTO.getYear()), Process::getYear, processReqDTO.getYear());
        return Convert.convert(new TypeReference<Page<ProcessResDTO>>() {
        },this.page(page, eq));
    }
}
